home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / dbkit / DBRecordStream.h < prev    next >
Text File  |  1992-09-08  |  5KB  |  174 lines

  1. /*
  2. **      DBRecordStream.h
  3. **      Database Kit, Release 3.0
  4. **      Copyright (c) 1992, NeXT Computer, Inc.  All rights reserved. 
  5. */
  6.  
  7. #import <objc/Object.h>
  8. #import <dbkit/protocols.h>
  9. #import <dbkit/enums.h>
  10.  
  11. @class List;
  12. @class DBDatabase;
  13. @class DBQualifier;
  14. @class DBValue;
  15.  
  16. @interface DBRecordStream : Object
  17. {
  18. @public
  19.   id delegate;
  20.   id source;
  21.   id properties;
  22.   id database;
  23.  
  24. @private
  25.   id _keys;
  26.   id _sorts;
  27.   int _qualifierMark;
  28.  
  29. @protected
  30.   id _selectBinder;
  31.   id _modifyBinder;
  32.   id _private;
  33.   short    _status;
  34.   struct {
  35. #if    __BIG_ENDIAN__
  36.     BOOL isModified:1;
  37.     BOOL newRecord:1;
  38.     BOOL freeSource:1;
  39.     BOOL freeQualifier:1;
  40.     int _RESERVED:12;
  41. #else    __BIG_ENDIAN__
  42.     int _RESERVED:12;
  43.     BOOL freeQualifier:1;
  44.     BOOL freeSource:1;
  45.     BOOL newRecord:1;
  46.     BOOL isModified:1;
  47. #endif    __BIG_ENDIAN__
  48.   } _flags;
  49. }
  50.  
  51.  
  52. /*
  53. ** clear causes the entire RecordStream to be reset.  Empty will leave the
  54. **  orderings, keys, and properties intact.
  55. */
  56. - init;
  57. - empty;
  58. - clear;
  59. - free;
  60.  
  61. /*
  62. ** Any binders used by the recordStream will have the binderDelegate as 
  63. **  their delegate.
  64. */
  65. - delegate;
  66. - binderDelegate;
  67. - setDelegate:newDelegate;
  68. - setBinderDelegate:newDelegate;
  69.  
  70. /*
  71. ** setProperties: will reset the keys list to contain any properties that
  72. **  respond YES to isKey -- the keys can be read and modified after this
  73. **  by calling getKeys and/or setKeys:
  74. **
  75. ** The entity for every property in the list submitted must match the entity
  76. **  of the RecordList, otherwise the entire operation fails.
  77. */
  78.  
  79. - (List*)getProperties:(List*)returnList;
  80. - (List*)setProperties:(List*)aPropertyList ofSource:aSource;
  81. - (List*)getKeyProperties:(List*)returnList;
  82. - (List*)setKeyProperties:(List*)aPropertyList;
  83.  
  84. - addRetrieveOrder:(DBRetrieveOrder)anOrder for:(id<DBProperties>)aProperty;
  85.  
  86. - fetchUsingQualifier:(DBQualifier*)aQualifier;
  87. - cancelFetch;
  88.  
  89. - (BOOL)isModified;
  90. - (BOOL)isNewRecord;
  91. - (BOOL)isReadOnly;
  92. - (DBRecordRetrieveStatus)currentRetrieveStatus;
  93.  
  94. /*
  95. ** saveModifications returns the number of records successfully modified and
  96. **  sent to the database.  For the RecordStream, this will always be either
  97. **  0, 1, or -1 on failure.
  98. */
  99. - (unsigned)saveModifications;
  100.  
  101. /*
  102. ** These methods are the only way to access the contents of the record
  103. */
  104. - getValue:(DBValue*)aValue forProperty:aProperty;
  105. - setValue:(DBValue*)aValue forProperty:aProperty;
  106.  
  107. - getRecordKeyValue:(DBValue*)aValue;
  108.  
  109. /*
  110. ** Record management --
  111. **  Both newRecord and deleteRecord will return nil if they failed (and that
  112. **  failure was not condoned or caught by the delegate).  If they return
  113. **  nil, then the cursor has NOT been advanced; it still points at the
  114. **  same record!!!  In the same way, setNext will return nil
  115. **  if the cursor has not advanced due to a failure.
  116. **
  117. ** The delegate has the option of "approving" a failure, by returning
  118. **  YES from recordStream:willFailForReason:  If YES is returned, the cursor
  119. **  will advance and the failure will be ignored.  In this event, if there
  120. **  is an active transaction context, its up to the application to deal with
  121. **  commit/abort.  Otherwise, the failed record will NOT have been committed
  122. **  to the database.
  123. **
  124. ** If there is no delegate, or the delegate returns NO from
  125. **  recordStream:willFailForReason:, then the cursor will not advance and
  126. **  whatever action is underway will not occur.
  127. **
  128. ** setNext returns self if there are more records, and nil if at end.
  129. */
  130. - newRecord;
  131. - deleteRecord;
  132. - setNext;
  133.  
  134. @end
  135.  
  136. @interface Object (DBRecordStreamDelegate)
  137.  
  138. /*
  139. ** The delegate of the RecordStream is given the opportunity to continue
  140. **  the transaction or abort.  If the delegate returns YES from its
  141. **  recordList:willFailAt:reason: method, the list will attempt to abort
  142. **  a local transaction.  If the transaction is not "owned" by the recordList,
  143. **  it is the responsibility of the app to either rollback or commit.
  144. **  If YES is returned, the list will attempt the rest of its modifications.
  145. **
  146. ** If the database being accessed supports transactions, they
  147. **  should always be enabled before saving modifications.  It is, in general,
  148. **  both safer for the integrity of the data involved and much more
  149. **  efficient to do this.
  150. */
  151. - (BOOL)recordStream:aRecordStream willFailForReason:(DBFailureCode)aCode;
  152.  
  153. /*
  154. ** The recordStream normally verifies that a record still exists and is
  155. **  unique before modifying or deleting it.  The default mechanism is to
  156. **  do a "confirming select" on the DBDatabase using the key value, and
  157. **  then to compare all properties to see that they haven't changed.  (The
  158. **  select is usually a locking select.)
  159. **
  160. ** This entire mechanism can be replaced by implementing the following
  161. **  delegate method.  In this case, verification and locking are up to the
  162. **  delegate object -- if YES is returned, the record is considered to
  163. **  be verified, and modification will proceed.  If NO is returned, the
  164. **  record will not be modified.  This may also cause the entire containing
  165. **  saveModifications: to fail, depending on the transaction model being
  166. **  used.
  167. **
  168. ** The only recordStream/recordList method that should be called during this
  169. **  delegate method is getValue:forProperty:
  170. */
  171. - (BOOL)recordStreamPrepareCurrentRecordForModification:aRecordStream;
  172.  
  173. @end
  174.